// ==UserScript== // @name 宝可梦点击(Poke Clicker)辅助脚本 自动孵蛋模块 // @namespace PokeClickerHelper // @version 0.1.7 // @description 全自动高效孵化宝可梦、宝可梦蛋、化石 // @author DreamNya // @match https://www.pokeclicker.com // @match https://g8hh.github.io/pokeclicker/ // @match https://pokeclicker.g8hh.com // @match https://yx.g8hh.com/pokeclicker/ // @icon data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/319hf99fYX/fX2F/319hf8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////////////////////////99fYX/fX2F/319hf8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////wAAAP8AAAD/fX2F/319hf99fYX/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////8AAAD/AAAA/wAAAP99fYX/fX2F/wAAAP8AAAD/AAAA/319hf8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/HBT//xwU//8AAAD//////319hf8AAAD/Dgim/w4Ipv8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAD/HBT//xwU//8cFP//HBT//wAAAP8AAAD/Dgim/w4Ipv8OCKb/Dgim/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAA/xwU//8cFP//HBT//xwU/44cFP//HBT//xwU//8cFP//Dgim/w4Ipv8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/HBT//xwU/47/////HBT/jhwU//8cFP//HBT//w4Ipv8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/xwU//8cFP//HBT/jhwU//8OCKb/Dgim/w4Ipv8OCKb/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/xwU//8OCKb/Dgim/w4Ipv8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAPw/AADwDwAA4AcAAOAHAADAAwAAwAMAAMADAADAAwAA4AcAAOAHAADwDwAA/D8AAP//AAD//wAA//8AAA== // @grant none // @license MIT // @run-at document-end // ==/UserScript== /* global App, $, PokeClickerHelper, Underground, PartyController, GameConstants, player, ItemList, CaughtStatus, PokemonHelper, Settings, pokemonMap, PokemonCategories */ if (typeof PokeClickerHelper == typeof void 0) { alert('宝可梦点击(Poke Clicker)辅助脚本 自动孵蛋模块加载失败\n\n未找到核心模块,需要先安装核心模块才可正常使用\n\n论坛主页:https://bbs.tampermonkey.net.cn/forum.php?mod=viewthread&tid=3842') window.open("https://bbs.tampermonkey.net.cn/forum.php?mod=viewthread&tid=3842") return } //UI相关 PokeClickerHelper.UIDOM.push(`
`) const fuc = () => { //非挑战模式区域减益隐藏 if (!App.game.challenges.list.regionalAttackDebuff.active()) $('#PokeClickerHelperBreedingRegionDebuffDiv').addClass('invisible') //TODO 孵化属性标签优化 //读取孵蛋类别 PokemonCategories.categories().map(i => i.name()).forEach((i, index) => { $('#PokeClickerHelperBreedingPriority').append(``) }) } //监听不要写在UICustomFuc中,避免读取DOM设置存储时多余触发监听事件 const listener = () => { $('#PokeClickerHelperToggleBreeding').on('click', function () { if (this.value == '结束') { PokeClickerHelper.restoreHook(PokeClickerHelper.hookGame.breeding) //还原hook方法 $('#PokeClickerHelperToggleBreeding').text(this.value = '开始') } else { PokeClickerHelper.applyHook(PokeClickerHelper.hookGame.breeding) //应用hook方法 $('#PokeClickerHelperToggleBreeding').text(this.value = '结束') } }) $("#PokeClickerHelperBreedingSortOption").on('change', function () { if ($("#PokeClickerHelperBreedingType").prop('value') == 'BreadingPokemon') { $("label:has(#PokeClickerHelperBreedingCalcEV)").toggleClass('d-none', this.value != '6') } }) $("#PokeClickerHelperBreedingCalcEV").on('change', function () { Settings.setSettingByName('breedingIncludeEVBonus', this.checked) }) $("#PokeClickerHelperBreedingType").on('change', function () { const isPokemon = this.value == 'BreadingPokemon' $("label:has(#PokeClickerHelperBreedingInvert)").toggleClass('invisible', !isPokemon) $("label:has(#PokeClickerHelperBreedingUncaught)").toggleClass('d-none', isPokemon) $("#PokeClickerHelperBreedingType").parent().siblings().find('select').attr('disabled', !isPokemon) $("#PokeClickerHelperBreedingRow2 select").attr('disabled', !isPokemon) $("label:has(#PokeClickerHelperBreedingCalcEV)").toggleClass('d-none', !isPokemon || $("#PokeClickerHelperBreedingSortOption").prop("value") != '6') }) } PokeClickerHelper.UICustomFuc.push(fuc); PokeClickerHelper.UIlistener.push(listener); //暴露对象方法到全局 const BreedingHelper = {}; PokeClickerHelper.BreedingHelper = BreedingHelper; //满步数自动孵蛋、有空位自动孵蛋 hook方法 const autoHatch = function (Game) { const replacement = [['this._queueList().length && ', ''], [/^/, "PokeClickerHelper.BreedingHelper.AutoBreeding();"]]; PokeClickerHelper.HookFuc(Game.breeding, 'progressEggs', replacement, 'amount'); PokeClickerHelper.restoreHook(PokeClickerHelper.hookGame.breeding) } PokeClickerHelper.addHook('Game', autoHatch) /* 孵完蛋后自动孵蛋【废弃 改为只hook autoHatch】 const autoBreed = function (Game) { const replacement = [[/}\n $/, 'PokeClickerHelper.BreedingHelper.AutoBreeding()}']]; PokeClickerHelper.HookFuc(Game.breeding, 'hatchPokemonEgg', replacement, 'index'); //PokeClickerHelper.BreedingHelper.AutoBreeding() } PokeClickerHelper.addHook('Game', autoBreed) */ //委托函数 利用语法糖配合解构减少冗余代码 BreedingHelper.AutoBreeding = () => { if (!App.game.breeding.hasFreeEggSlot()) return let value = [...document.querySelectorAll('#PokeClickerHelperBreeding select')].map(i => i.value) if (value.length > 0) BreedingHelper[value.shift()](value) } //tick方法孵蛋【废弃 改为hook方法调用孵蛋代码】 //PokeClickerHelper.hookGameTickList.add(BreedingHelper.AutoBreeding) //利用解构减少代码 //孵宝可梦 BreedingHelper.BreadingPokemon = ([sortOption, shiny, region, type1, type2, Priority]) => { let direction = document.querySelector("#PokeClickerHelperBreedingInvert").value == 'false' let pokemonArr = App.game.party.caughtPokemon pokemonArr.sort(PartyController.compareBy(sortOption * 1, direction, region * 1)) if ((shiny = JSON.parse(shiny)) != 'all') pokemonArr.sort(function (a) { return a.shiny == shiny ? -1 : 1 }) if (Priority != '0') pokemonArr.sort(function (a) { return a.category == Priority ? -1 : 1 }) for (let pokemon of pokemonArr) { if (!App.game.breeding.hasFreeEggSlot()) break if (pokemon.level >= 100 && !pokemon.breeding) { if (Priority == 0 || (Priority != 0 && pokemon.category != Priority)) { type1 = type1 * 1 type2 = type2 * 1 if (type1 + type2 != -4) { if (type1 == -1) type1 = void 0 if (type2 == -1) type2 = void 0 const [pokemonType1, pokemonType2] = pokemonMap[pokemon.name].type if ((type1 != -2 && type1 != pokemonType1) || (type2 != -2 && type2 != pokemonType2)) continue } } //console.log('孵宝可梦',pokemon.displayName) App.game.breeding.addPokemonToHatchery(pokemon) } } } //孵蛋 BreedingHelper.BreadingEgg = () => { let avaiableEgg = Object.keys(GameConstants.EggItemType).filter(e => isNaN(e)).filter(x => player._itemList[x]()); let onlyUncaught = document.querySelector("#PokeClickerHelperBreedingUncaught").value == 'true' if (onlyUncaught) avaiableEgg = avaiableEgg.filter(i => ItemList[i].getCaughtStatus() == CaughtStatus.NotCaught) avaiableEgg = avaiableEgg.flatMap(i => Array(Math.min(player._itemList[i](), 4)).fill(i)) for (let egg of avaiableEgg) { if (!App.game.breeding.hasFreeEggSlot()) break ItemList[egg].use(); } } //孵化石 BreedingHelper.BreadingFossil = () => { let avaiableFossil = Object.keys(GameConstants.FossilToPokemon).map(f => player.mineInventory().find(i => i.name == f)).filter(f => f ? f.amount() : false) let onlyUncaught = document.querySelector("#PokeClickerHelperBreedingUncaught").value == 'true' avaiableFossil = avaiableFossil.filter(i => { let flag = PokemonHelper.calcNativeRegion(GameConstants.FossilToPokemon[i.name]) <= player.highestRegion() if (onlyUncaught) flag = flag && PartyController.getCaughtStatusByName(GameConstants.FossilToPokemon[i.name]) == CaughtStatus.NotCaught return flag }) avaiableFossil = avaiableFossil.map(i => Array(i.amount()).fill(i.id)).flat() for (let fossil of avaiableFossil) { if (!App.game.breeding.hasFreeEggSlot()) break Underground.sellMineItem(fossil) } }